<div class="lottery">
	<div class="nav">
		<div class="nav-li focus">抽奖活动</div>
	</div>
	<hr />
	<div class="infobox">
		<div class="lottery-edit">
		{{#if $Cache.lottery.current_lottery._id}}
			<h4>修改抽奖活动 
				<android:paperbutton event-click="{{'$Event.lottery.update_lottery'}}">确定修改</android:paperbutton>
				<android:paperbutton event-click="{{'$Event.lottery.cancel_update_lottery'}}">取消修改</android:paperbutton>
			</h4>
		{{#else}}
			<h4>新增抽奖活动
				<android:paperbutton event-click="{{'$Event.lottery.add_lottery'}}">确定新增</android:paperbutton>
			</h4>
		{{/if}}
	<table class="paper-table">
		<thead>
			<td style="width:50%">基础信息</td>
			<td style="width:50%">奖品信息</td>
		</thead>
		<tr>
			<td>
				<div class="item">
					<android:input label="抽奖活动标题" description="字数限制：{{config.server_config.lotteryTitleLength}}字" value="{{$Cache.lottery.current_lottery.title}}" bind-input="{{'$Cache.lottery.current_lottery.title'}}"></android:input>
				</div>
				<div class="item hr">
					<p>活动开始时间：<i>不填代表随时都可以开始活动</i></p>
					<android:datePicker value="{{$Cache.lottery.current_lottery.startTime}}" placeholder="未设置，手动开始活动" bind-input="{{'$Cache.lottery.current_lottery.startTime'}}"></android:datePicker>
					<inputnumber min=0 loop=300000 value="{{$Cache.lottery.current_lottery.startTime}}" bind-input="{{'$Cache.lottery.current_lottery.startTime'}}" value-map-*="$Handle.moment.format_HH_mm"></inputnumber>
				</div>
				<div class="item hr">
					<p>活动结束时间（活动开始后可变更）：<i>如果到这个时间点活动会自动结束</i></p>
					<android:datePicker value="{{($Cache.lottery.current_lottery.endTime&&$Cache.lottery.current_lottery.endTime!==window.Number.MAX_VALUE)?$Cache.lottery.current_lottery.endTime:''}}" placeholder="未设置，手动结束活动" bind-input="{{'$Cache.lottery.current_lottery.endTime'}}"></android:datePicker>
					<inputnumber min=0 loop=300000 value="{{$Cache.lottery.current_lottery.endTime}}" bind-input="{{'$Cache.lottery.current_lottery.endTime'}}" value-map-*="$Handle.moment.format_HH_mm"></inputnumber>
				</div>
				<div class="item hr">
					每人可抽奖的次数
					<inputnumber min=1 loop=1 value="{{$Cache.lottery.current_lottery.visitor_times_limit}}" bind-input="{{'$Cache.lottery.current_lottery.visitor_times_limit'}}"></inputnumber>
				</div>
				{{#if $Cache.lottery.current_lottery.visitor_times_limit>1}}
				<div class="item hr">
					多次抽奖的时间间隔
					<inputnumber min=0 loop=900000 style="width:150px;" value="{{$Cache.lottery.current_lottery.visitor_interval_limit}}" bind-input="{{'$Cache.lottery.current_lottery.visitor_interval_limit'}}" value-map-0="默认12小时" value-map-*="$Handle.lottery.visitor_interval_limit"></inputnumber>
				</div>
				{{/if}}
			</td>
			<td>
				
				{{#each $Cache.lottery.current_lottery.awards}}
<div class="four-hr item">
	<div class="input-inline-block">
		<android:input value="{{title}}" bind-input="{{'title'}}" label="奖项名" description="比如：“一等奖”"></android:input>
		<android:paperbutton event-click="{{'$Top.$Event.lottery.current_lottery_remove_award'}}">删除奖项</android:paperbutton>
	</div>
	<div class="hr">
		<android:selectSearch use-value-as-result="true" value="{{type}}" placeholder="请选择奖品类型" bind-input="{{'type'}}">
			{{#each $Top.$Cache.LOTTERY_TYPE_array}}
			<optionItem value="{{value}}" search-data="{{value+key}}">{{key}}</optionItem>
			{{/each}}
		</android:selectSearch>
		{{#> "bus-admin-lottery-award-type-"+type, "$This", type}}
		<xmp type="template" name="bus-admin-lottery-award-type-ticket_factory">
			<span style="padding-left: 20px;" >
				<android:input label="优惠券的ID" value="{{content_id}}" bind-input="{{'content_id'}}"></android:input>
			</span>
		</xmp>
		<xmp type="template" name="bus-admin-lottery-award-type-goods">
			<span style="padding-left: 20px;" >
				<android:input label="商品的ID" value="{{content_id}}" bind-input="{{'content_id'}}"></android:input>
			</span>
		</xmp>
		<xmp type="template" name="bus-admin-lottery-award-type-_custom_award">
			<div >
				<div style="display:inline-block;width:35%;">
					<img-uploader
						upload-server-url="{{config.other.upload_image}}"
						text="上传奖品图片"
						bind-input-key="content.img_url"
						url="{{content.img_url}}"
						bind-status="{{'_img_url_upload_status'}}"
						style="display:inline-block;"
						max-width="512"
						>
					</img-uploader>
				</div>
				<div style="display:inline-block;width:65%;vertical-align: top;">
					<android:input label="奖品标题" value="{{content.title}}" bind-input="{{'content.title'}}"></android:input>
					<android:input label="奖品介绍" value="{{content.intro}}" bind-input="{{'content.intro'}}"></android:input>
				</div>
			</div>
		</xmp>
	</div>
	<div class="hr">
		<span>
			奖品数量：<inputnumber min=1 loop=1 value="{{win_number}}" bind-input="{{'win_number'}}"></inputnumber>
		</span>
		<span>
			预计参与人数：<inputnumber min=1 loop=10 value="{{join_number}}" bind-input="{{'join_number'}}"></inputnumber>
		</span>
	</div>
	<p><i>平均每 <b>{{#Fixed (join_number||1)/(win_number||1)}}</b> 人会获得 <b>1</b> 奖品</i></p>
</div>
				{{/each}}
				<android:paperbutton style="width:100%;" event-click="{{'$Event.lottery.current_lottery_add_award'}}">
                	<android:icon type="image-control-point"></android:icon> 添加奖项
                </android:paperbutton>
			</td>
		</tr>
		<thead>
			<td colspan=2>
				抽奖活动详细介绍
			</td>
		</thead>
		<tr>
			<td colspan=2>
				<ueditor 
					style="display: inline-block;"
					bind-input="{{'$Cache.lottery.current_lottery.detail_content'}}" 
					bind-status="{{'$Cache.lottery.current_lottery._detail_content_img_upload_status'}}"
					value="{{$Cache.lottery.current_lottery.detail_content}}" >
					<!-- 但init-key所对应的内容开始存在时，初始化编辑区域 -->
				</ueditor>
			</td>
		</tr>
	</table>
		</div>
		<div class="lottery-list">
			<h4>抽奖活动列表</h4>
			<table class="paper-table">
				<thead>
					<td>序号</td>
					<td>抽奖活动标题</td>
					<td>创建时间</td>
					<td>操作</td>
				</thead>
				{{#each $Cache.lottery.list}}
				<tr>
					<td>{{$Index+1}}</td>
					<td>{{title}}</td>
					<td>{{#Time create_time}}</td>
					<td>
						<android:paperbutton event-click="{{'$Top.$Event.lottery.to_update_lottery'}}">修改</android:paperbutton>
						<android:paperbutton event-click="{{'$Top.$Event.lottery.remove_lottery'}}">删除</android:paperbutton>
						<android:paperbutton event-click="{{'$Top.$Event.lottery.toggle_winner_list'}}">中奖信息
							<android:icon style="font-size: 1em;transform: scale(1.3);line-height: 1em;" type="{{$Private.show_winner_list?'navigation-expand-less':'navigation-expand-more'}}"></android:icon>
						</android:paperbutton>
					</td>
				</tr>
				{{#> "lottery-winner_list-info", "$This", $Private.show_winner_list}}
				<xmp type="template" name="lottery-winner_list-info">
					<tr>
						<td colspan="4" style="padding-left:2em;">
							<table class="paper-table">
								<thead>
									<td>序号</td>
									<td>奖项</td>
									<td>用户名</td>
									<td>手机</td>
									<td>邮箱</td>
								</thead>
								{{#if $ParentPM.$Private.total_winner_length}}
								{{#each awards}}
									{{#each winner_list_info}}
									<tr>
										<td>{{$Caller.$Index}}·{{$Index}}</td>
										<td>{{$Caller.title}}</td>
										<td>{{info.name}}</td>
										<td>{{#if info.mobile}}{{info.mobile}}{{#else}}<i>无</i>{{/if}}</td>
										<td>{{#if info.email}}{{info.email}}{{#else}}<i>无</i>{{/if}}</td>
									</tr>
									{{/each}}
								{{/each}}
								{{#else}}
								<tr>
									<td colspan="5">
										<i>暂无获奖用户</i>
									</td>
								</tr>
								{{/if}}
							</table>
						</td>
					</tr>
				</xmp>
				{{/each}}
			</table>
		</div>
	</div>
</div>

<style>
	.lottery .paper-table .item {
		margin-top: 1em;
	}
	.lottery .paper-table .item p>i{
		float: right;
	}
	.lottery-edit .paper-table tr>td{
		padding: 8px;
		vertical-align: top;
	}
	.hr{
		padding-top: 1.5em;
	}
	.four-hr{
		border: 1px dotted #555558;
		border-radius: 11px;
		display: block;
		margin: 6px 0;
		padding: 0.5em;
	}
	.input-inline-block .android-input{
		display: inline-block;
		width: 75%;
	}
	.input-inline-block .paper-button{
		float: right;
	}
	.lottery-list .paper-table tr>td{
		text-align: center;
	}
</style>